#include "system/thread/Thread.hpp"
#include <pthread.h>

namespace SystemThread
{
	Thread::~Thread()
	{

	}

	void Thread::join()
	{
		pthread_join(_thread, NULL);
	}

	void Thread::run()
	{
		if(pthread_create(&_thread, NULL, &runWrapped, this) != 0)
			throw ThreadCreationException();
	}

	void Thread::exit()
	{
		pthread_exit(0);
	}


	void Thread::kill()
	{
		_mutex.lock();
		{
			_alive = false;
		}
		_mutex.unlock();
		this->join();
	}

	bool Thread::isAlive()
	{
		bool aAlive;
		_mutex.lock();
		{
			aAlive = _alive;
		}
		_mutex.unlock();
		return aAlive;
	}

};
